﻿using ETC.DLEDLightingSystemPlus.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ETC.DLEDLightingSystemPlus.Models
{
    public class TestCommand : Bandit.UI.MVVM.NotifyObject
    {
        private int _TestModelCode;

        public int TestModelCode { get { return _TestModelCode; } set { _TestModelCode = value; ComputeIoutCurrentValue(); OnPropertyChanged(nameof(TestModelCode)); } }

        private bool _IsVLedSet = true;
        public bool IsVLedSet { get { return _IsVLedSet; } set { _IsVLedSet = value; OnPropertyChanged(nameof(IsVLedSet)); } }

        private double _DvledValue = 6.72;

        public double DvledValue { get { return _DvledValue; } set { _DvledValue = value; OnPropertyChanged(nameof(DvledValue)); } }


        private bool _IsOCPOVPSet = true;
        public bool IsOCPOVPSet { get { return _IsOCPOVPSet; } set { _IsOCPOVPSet = value; OnPropertyChanged(nameof(IsOCPOVPSet)); } }

        private double _DvLedOvpValue = 8;
        public double DvLedOvpValue { get { return _DvLedOvpValue; } set { _DvLedOvpValue = value; OnPropertyChanged(nameof(DvLedOvpValue)); } }

        private double _DvLedOcpValue = 4;
        public double DvLedOcpValue { get { return _DvLedOcpValue; } set { _DvLedOcpValue = value; OnPropertyChanged(nameof(DvLedOcpValue)); } }

        private double _DICOvpValue = 3.4;
        public double DICOvpValue { get { return _DICOvpValue; } set { _DICOvpValue = value; OnPropertyChanged(nameof(DICOvpValue)); } }

        private double _DICOcpValue = 0.2;
        public double DICOcpValue { get { return _DICOcpValue; } set { _DICOcpValue = value; OnPropertyChanged(nameof(DICOcpValue)); } }

        private bool _IsMCSet = true;

        public bool IsMCSet { get { return _IsMCSet; } set { _IsMCSet = value; OnPropertyChanged(nameof(IsMCSet)); } }

        private int _IMCValue = 1;

        public int IMCValue { get { return _IMCValue; } set { _IMCValue = value; ComputeIoutCurrentValue(); OnPropertyChanged(nameof(IMCValue)); } }

        private bool _IsDCSet = true;

        public bool IsDCSet { get { return _IsDCSet; } set { _IsDCSet = value; OnPropertyChanged(nameof(IsDCSet)); } }

        private int _IDCValue = 1;

        public int IDCValue { get { return _IDCValue; } set { _IDCValue = value; ComputeIoutCurrentValue(); OnPropertyChanged(nameof(IDCValue)); } }

        private bool _IsBCSet = true;

        public bool IsBCSet { get { return _IsBCSet; } set { _IsBCSet = value; OnPropertyChanged(nameof(IsBCSet)); } }

        private int _IBCValue = 1;

        public int IBCValue { get { return _IBCValue; } set { _IBCValue = value; ComputeIoutCurrentValue(); OnPropertyChanged(nameof(IBCValue)); } }


        private double _IoutCurrentValue;

        public double IoutCurrentValue
        {
            get { return _IoutCurrentValue; }
            set
            {
                _IoutCurrentValue = value;
                OnPropertyChanged(nameof(IoutCurrentValue));
            }
        }

        #region 计算IOut电流

        public void ComputeIoutCurrentValue()
        {
            switch (this.TestModelCode)
            {
                case 1:
                case 8:
                case 9:
                    {
                        IoutCurrentValue = ComputeIoutForAU586A();
                    }
                    break;
                case 11:
                    {
                        IoutCurrentValue = ComputeIoutForSD058A();

                    }
                    break;
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 12:
                    {
                        IoutCurrentValue = ComputeIoutForBH003_Bh004();
                    }
                    break;
                case 7:
                    {

                    }
                    break;
                default:
                    break;
            }

        }

        private double ComputeIoutForAU586A()
        {
            int MC = 0;

            MC = this.IMCValue;

            return Math.Round(60.0 * MC / 255, 3);
        }
        private double ComputeIoutForSD058A()
        {
            int MC = 0;

            MC = this.IMCValue;

            return Math.Round(30.0 * MC / 255, 3);
        }
        private double ComputeIoutForBH003_Bh004()
        {
            double iMax = 0.0;
            int MC = 0;
            int DC = 0;
            int BC = 0;

            BC = this.IBCValue;
            DC = this.IDCValue;
            MC = this.IMCValue;

            switch (MC)
            {
                case 0:
                    {
                        iMax = 3.2;
                    }
                    break;
                case 1:
                    {
                        iMax = 8.0;
                    }
                    break;
                case 2:
                    {
                        iMax = 11.2;
                    }
                    break;
                case 3:
                    {
                        iMax = 15.9;
                    }
                    break;
                case 4:
                    {
                        iMax = 19.1;
                    }
                    break;
                case 5:
                    {
                        iMax = 23.9;
                    }
                    break;
                case 6:
                    {
                        iMax = 27.1;
                    }
                    break;
                case 7:
                    {
                        iMax = 31.9;
                    }
                    break;
                default:
                    break;
            }

            return Math.Round(iMax * (0.262 + 0.738 * DC / 127) * (0.1 + 0.9 * BC / 127), 3);
        }


        #endregion


        public TestCommand()
        {

        }

        public void InitTestCommand()
        {
            TestModelCode = 1;
            IsVLedSet = true;
            DvledValue = 6.72;
            IsOCPOVPSet = true;
            DvLedOvpValue = 7;
            DvLedOcpValue = 3;
            DICOvpValue = 3.5;
            DICOcpValue = 0.05;
            IsMCSet = true;
            IMCValue = 1;
            IsDCSet = false;
            IDCValue = 1;
            IsBCSet = false;
            IBCValue = 1;
        }

        public TestCommand(int testModelCode, bool isVLedSet, double dvledValue, bool isOCPOVPSet, double dvLedOvpValue, double dvLedOcpValue, double dICOvpValue, double dIcOcpValue, bool isMCSet, int iMCValue, bool isDCSet, int iDCValue, bool isBCSet, int iBCValue)
        {
            TestModelCode = testModelCode;
            IsVLedSet = isVLedSet;
            DvledValue = dvledValue;
            IsOCPOVPSet = isOCPOVPSet;
            DvLedOvpValue = dvLedOvpValue;
            DvLedOcpValue = dvLedOcpValue;
            DICOvpValue = dICOvpValue;
            DICOcpValue = dIcOcpValue;
            IsMCSet = isMCSet;
            IMCValue = iMCValue;
            IsDCSet = isDCSet;
            IDCValue = iDCValue;
            IsBCSet = isBCSet;
            IBCValue = iBCValue;
        }
    }

    public class TestCodeModel
    {
        public string Name { get; set; }

        public int TestModelCode { get; set; }

        public TestCodeModel() { }

        public TestCodeModel(string Name, int TestModelCode)
        {
            this.Name = Name;
            this.TestModelCode = TestModelCode;

        }
    }

    public class StationModel:Bandit.UI.MVVM.NotifyObject
    {
        private string _Name;
        public string Name { get { return _Name; } set { _Name = value;OnPropertyChanged(nameof(Name)); } }

        private string _StationCode;
        public string StationCode { get { return _StationCode; } set { _StationCode = value;OnPropertyChanged(nameof(StationCode)); } }

        public StationModel() { }

        public StationModel(string Name, string StationCode)
        {
            this.Name = Name;
            this.StationCode = StationCode;

        }
    }

    public class TestCodeCurrentUpperModel
    {
        public double CurrentUpper { get; set; }

        public int TestModelCode { get; set; }

        public TestCodeCurrentUpperModel() { }

        public TestCodeCurrentUpperModel(double CurrentUpper, int TestModelCode)
        {
            this.CurrentUpper = CurrentUpper;
            this.TestModelCode = TestModelCode;

        }
    }

    public class PWMCodeModel
    {
        public string Name { get; set; }

        public int PWMCode { get; set; }

        public PWMCodeModel() { }

        public PWMCodeModel(string Name, int iPWMCode)
        {
            this.Name = Name;
            this.PWMCode = iPWMCode;

        }

    }

    public class LogInfoExcelMode
    {
        public string Name { get; set; }

        public string ExcelPath { get; set; }

        public LogInfoExcelMode() { }

        public LogInfoExcelMode(string Name, string path)
        {
            this.Name = Name;
            this.ExcelPath = path;

        }
    }
}
